package top.xia17.plugins.fast.user.dao.repository;

import top.xia17.plugins.fast.common.database.jpa.extension.Xia17JpaRepository;
import org.springframework.data.jpa.repository.Query;
import top.xia17.plugins.fast.user.dao.entity.Menu;

import java.util.Collection;
import java.util.List;

/**
 * 菜单repository
 *
 * @author xia17
 * @since 2021/7/29 11:36
 */
public interface MenuRepository extends Xia17JpaRepository<Menu, Long> {


    /**
     * 查询角色拥有的菜单
     *
     * @param roleIds 角色
     * @param mobile  是否移动端
     * @return /
     */
    @Query(nativeQuery = true, value = "SELECT sys_menu.* FROM sys_menu " +
            " INNER JOIN sys_roles_menus ON sys_menu.id = sys_roles_menus.menu_id " +
            "WHERE sys_menu.mobile = ?2 AND role_id IN ?1")
    List<Menu> myFindMenuTreeByRoles(Collection<Long> roleIds, Boolean mobile);

    /**
     * 查询角色拥有的菜单
     *
     * @param roleIds 角色
     * @return /
     */
    @Query(nativeQuery = true, value = "SELECT sys_menu.* FROM sys_menu " +
            " INNER JOIN sys_roles_menus ON sys_menu.id = sys_roles_menus.menu_id " +
            "WHERE role_id IN ?1")
    List<Menu> myFindMenuTreeByRoles(Collection<Long> roleIds);
}
